package threading;

/**
 * @author krystal
 * @date 2022/11/24 16:36
 */
//懒汉模式来实现单例模式
class SingletonLazy{
    private volatile static SingletonLazy instance=new SingletonLazy();

    public static SingletonLazy getInstance(){
        if (instance==null){
            synchronized (SingletonLazy.class){
                if (instance==null){
                    instance=new SingletonLazy();
                }
            }
        }
        return instance;
    }

    private SingletonLazy(){

    }
}

public class Demo21 {
    public static void main(String[] args) {
        SingletonLazy instance=SingletonLazy.getInstance();
    }
}
